import React, { Component } from 'react'
import { ListBox } from '../../../components'
import UpdateWorkareaPage from './UpdateNew'
import UpdateWorkareaPageUp from './UpdateNewUp'
import InfoPage from './Info'
import OpenPage from './Open'
import CloseNewPage from './CloseNew'
import UpdatePage from './Update'
import { fetchData } from '../../../components/AjaxConsumer'
import { Button, Modal, Form, Input, Radio, Upload, Icon } from 'antd';

export default class ListProStroagePage extends Component {
    constructor(props) {
        super(props);
        this.state = {
            tableColumn: {},
            searchComponentData: [],
            visible: false,
        };
        //行操作列表
        this.rowOperation = [
            
        ];
        //header 操作列表
        this.headerOperation = [
            {
                handleName: 'close',
                showName: '冻结',
                iconClass: 'edit',
                permission: 'prostorage-freeze'
            },
            {
                handleName: 'open',
                showName: '解冻',
                iconClass: 'edit',
                permission: 'prostorage-unfreeze'
            }
            ,{
                handleName: 'info',
                showName: '查看',
                iconClass: 'info'
            }
        ];

        //table列表展示列配置
        //showName、columnName 必有属性， columnWidth 可选，默认100, columnHidden: true 列隐藏
        this.tableColumn = {
            storageKey: 'listProStroagePage',
            data: [
                // {
                //     showName: '条码',
                //     columnName: 'barcode'
                // },
                {
                    showName: '型号',
                    columnName: 'model',
                    columnWidth:120
                }, {
                    showName: '品名',
                    columnName: 'productName',
                    columnWidth:120
                }, {
                    showName: '定量',
                    columnName: 'density',
                },{
                    showName: '规格',
                    columnName: 'spec',
                    columnWidth:120
                },
                //  {
                //     showName: '类型',
                //     columnName: 'type',
                //     showOption: [//页面显示配置
                //         {
                //             optionKey: '0',
                //             optionShow: '正品'
                //         }, {
                //             optionKey: '1',
                //             optionShow: '样品'
                //         }
                //     ]
                // },
                //  {
                //     showName: '生产机号',
                //     columnName: 'machinenumber'
                // },
                {
                    showName: '等级',
                    columnName: 'grade',
                    showOption: [//页面显示配置
                        {
                            optionKey: '1',
                            optionShow: '一等品'
                        }, {
                            optionKey: '2',
                            optionShow: '二等品'
                        }, {
                            optionKey: '3',
                            optionShow: '处理品'
                        }
                    ]
                },{
                    showName: '级别',
                    columnName: 'level',
                },{
                    showName: '库存数量',
                    columnName: 'iventAmount',
                },{
                    showName: '可用数量',
                    columnName: 'availAmount',
                },{
                    showName: '总冻结数量',
                    columnName: 'lockAmount',
                },{
                    showName: '库存重量',
                    columnName: 'iventWeight',
                },{
                    showName: '可用重量',
                    columnName: 'availWeight',
                },{
                    showName: '总冻结重量',
                    columnName: 'lockWeight',
                },
                // {
                //     showName: '排产时间',
                //     columnName: 'proPlanDate',
                // },{
                //     showName: '生产时间',
                //     columnName: 'proManuDate',
                // },
                //{
                //    showName: '单位',
                //    columnName: 'unit'
                //},
                // {
                //     showName: '仓库',
                //     columnName: 'whCode'
                // }, {
                //     showName: '区域',
                //     columnName: 'wdCode'
                // }, {
                //     showName: '库区',
                //     columnName: 'waCode'
                // },
                 {
                    showName: '仓库',
                    columnName: 'wlCode'
                },
                // {
                //     showName: '状态',
                //     columnName: 'barcodeStatus'
                // },
                // {
                //     showName: '冻结原因',
                //     columnName: 'lockReason'
                // },
                // {
                //     showName: '出库方式',
                //     columnName: 'userDefined1',
                //     showOption: [//页面显示配置
                //         {
                //             optionKey: '0',
                //             optionShow: '正常出库'
                //         }, {
                //             optionKey: '1',
                //             optionShow: '报废出库'
                //         }
                //     ]
                // },
                // {
                //     showName: '创建人',
                //     columnName: 'createBy'
                // },{
                //     showName: '创建时间',
                //     columnName: 'gmtCreate'
                // },{
                //     showName: '最后修改人',
                //     columnName: 'lastModifiedBy'
                // },{
                //     showName: '最后修改时间',
                //     columnName: 'gmtModified',
                //     columnWidth:120
                // },
                // {
                //     showName: '激活标记',
                //     columnName: 'activeFlag'
                // }
            ]
        };

        //搜索属性配置
        this.searchComponentData = [
            {
                showName: '型号类型',
                name: 'modelType',
                type: 'select',
                optionList: [
                   
                ]
            }, {
                showName: '产品类型',
                name: 'type',
                type: 'select',
                optionList: [
                    {
                        optionKey: '',
                        optionShow: ''
                    },
                     {
                        optionKey: '0',
                        optionShow: '正品'
                    }, {
                        optionKey: '1',
                        optionShow: '样品'
                    }
                ]
            }, {
                showName: '等级',
                name: 'grade',
                type: 'select',
                optionList: [
                    {
                        optionKey: '',
                        optionShow: ''
                    },{
                        optionKey: '1',
                        optionShow: '一等品'
                    },
                     {
                        optionKey: '2',
                        optionShow: '二等品'
                    }, {
                        optionKey: '3',
                        optionShow: '处理品'
                    }
                ]
            }, {
                showName: '级别',
                name: 'level',
                type: 'select',
                optionList: [
                    {
                        optionKey: '',
                        optionShow: ''
                    },{
                        optionKey: 'A',
                        optionShow: 'A'
                    },
                     {
                        optionKey: 'B',
                        optionShow: 'B'
                    }, {
                        optionKey: 'C',
                        optionShow: 'C'
                    }
                ]
            },
            {
                showName: '仓库',
                name: 'wlCode',
                type: 'select',
                url: '/base/data/location/get/wl_code'
            },
            {
                showName:'库存数量',
                name:'iventAmount',
                type: 'number',
                maxName:'iventAmountMax',
                minName:'iventAmountMin'
            },   
            {
                showName:'可用数量',
                name:'availAmount',
                type: 'number',
                maxName:'availAmountMax',
                minName:'availAmountMin'
            },
            {
                showName:'总冻结数量',
                name:'lockAmount',
                type: 'number',
                maxName:'lockAmountMax',
                minName:'lockAmountMin'
            },
            {
                showName:'库存重量',
                name:'iventWeight',
                type: 'number',
                maxName:'iventWeightMax',
                minName:'iventWeightMin'
            },    
            {
                showName:'可用重量',
                name:'availWeight',
                type: 'number',
                maxName:'availWeightMax',
                minName:'availWeightMin'
            },   
            {
                showName:'总冻结重量',
                name:'lockWeight',
                type: 'number',
                maxName:'lockWeightMax',
                minName:'lockWeightMin'
            },  
        ];

    }


    // componentWillMount() {
    //     const dicType = 'model_type_p';
    //     const options= {
    //         url: '/base/dic/get/' + dicType,
    //         type: 'get',
    //         condition:{}
    //     };
    //     //先写死，后面再改
    //     fetchData(this, options, this.dicInitCallBackHandle);
    // }

    // //下拉框 初始化
    // dicInitCallBackHandle = (resData)=>{
    //     //alert('resData' + JSON.stringify(resData, null, 4));
    //     let optionList = [];
    //     let tmp = {};
    //     tmp.optionKey = '';
    //     tmp.optionShow = '';
    //     optionList.push(tmp);
    //     resData.data.map( (e,index) => {
    //         let tmp = {};
    //         tmp.optionKey = e.dicCode;
    //         tmp.optionShow = e.dicName;
    //         optionList.push(tmp);
    //     });
    //     //alert('optionList' + JSON.stringify(optionList, null, 4));
    //     this.tableColumn.data[3].showOption = optionList;
    //     this.searchComponentData[0].optionList = optionList;
    // }


    rowHandles = (strHandles, rowObj) => {
        console.log("strHandles===ListResource=======", strHandles);
        if (strHandles === 'close') {
            this.closeHandle(rowObj);
        } 
        else if (strHandles == 'open') {
            this.openHandle(rowObj);
        }
        else if (strHandles == 'doubleClick') {
            this.infoHandle(rowObj);
        }
        else if (strHandles == 'info') {
            this.infoHandle(rowObj);
        }   
    }
    //
    closeHandle = (rowObj) => {
        if (rowObj.length == 0) {
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
            return;
        } else if (rowObj.length > 1) {
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
            return;
        } else {
            let pstData = {};
            pstData.model = rowObj[0].data.model;
            pstData.modelType = rowObj[0].data.modelType;
            pstData.wlCode = rowObj[0].data.wlCode;
            pstData.contractNo = rowObj[0].data.contractNo;
            pstData.type = rowObj[0].data.type;
            pstData.barcodeStatus = '0';
            const options = {
                url: '/product/insidewarehouse/storagesn/r/detail',
                type: 'get',
                condition: pstData
            };
            fetchData(this, options, (resData) => {
                this.refs.closeNewPage.editHandle(resData, rowObj[0].data.RawStorageId,
                    pstData.wlCode,pstData.contractNo, pstData.model, pstData.modelType, pstData.barcodeStatus);
            });
        }
    };
    openHandle = (rowObj) => {
        if (rowObj.length == 0) {
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
            return;
        } else if (rowObj.length > 1) {
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
            return;
        } else {
            let pstData = {};
            pstData.model = rowObj[0].data.model;
            pstData.modelType = rowObj[0].data.modelType;
            pstData.wlCode = rowObj[0].data.wlCode;
            pstData.contractNo = rowObj[0].data.contractNo;
            pstData.barcodeStatus = '1';
            console.log("rowObj[0].data.RawStorageId:****************" + rowObj[0].data.RawStorageId);
            const options = {
                url: '/product/insidewarehouse/storagesn/r/detail',
                type: 'GET',
                condition: pstData,
            };
            fetchData(this, options, (resData) => {
                this.refs.openPage.editHandle(resData, rowObj[0].data.RawStorageId,
                    pstData.wlCode,pstData.contractNo, pstData.model, pstData.modelType, pstData.barcodeStatus);
            });
        }
    };
    infoHandle = (rowObj) => {
        if (rowObj.length == 0) {
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
            return;
        } else if (rowObj.length > 1) {
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
            return;
        } else {
            let pstData = {};
            pstData.wlCode = rowObj[0].data.wlCode;
            pstData.contractNo = rowObj[0].data.contractNo;
            pstData.model = rowObj[0].data.model;
            pstData.modelType = rowObj[0].data.modelType;
            const options = {
                url: '/product/insidewarehouse/storagesn/r/detail',
                type: 'GET',
                condition: pstData,
            };
            fetchData(this, options, (resData) => {
                this.refs.infoPage.editHandle(resData, pstData);
            });

            //this.refs.listDetail.editHandle(rowObj[0].data);
        }
    };

    //刷新列表
    refreshHandle = () => {
        this.refs.listWorkarea.refreshHandle();
    }

    

    handleCancel = () => {
        this.setState({ visible: false });
        this.form.resetFields();

    }
    handleCreate = () => {
        const form = this.form;
        form.validateFields((err, values) => {
            if (err) {
                return;
            }

            console.log('Received values of form: ', values);
            form.resetFields();
            this.setState({ visible: false });
        });
    }
    saveFormRef = (form) => {
        this.form = form;
    }


    render() {
        //当左侧隐藏时，列表宽度加上左侧的宽度，
        //1、当前this.props.isHideLeft 是从页面组件containers/Main/main.js传过来
        //2、this.props.isHideLeft 最顶级赋值是在页面 containers/Main/main.js
        let isHideLeft = this.props.isHideLeft;

        return (
            <div>
                <ListBox
                    ref='listWorkarea'
                    title="成品库存查询"
                    isHideLeft={isHideLeft}
                    tableColumnData={this.tableColumn}
                    searchComponentData={this.searchComponentData}
                    url='/product/insidewarehouse/storage/list'
                    rowHandles={this.rowHandles}
                    rowOperation={this.rowOperation}
                    headerOperation={this.headerOperation}
                    isRowSingle="true"
                />

                <UpdateWorkareaPage
                    ref="updateWorkarea"
                    refreshHandle={this.refreshHandle}
                />
                <UpdateWorkareaPageUp
                    ref="updateWorkareaUp"
                    refreshHandle={this.refreshHandle}
                />
                <OpenPage
                    ref="openPage"
                    refreshHandle={this.refreshHandle}
                />

                <CloseNewPage
                    ref="closeNewPage"
                    refreshHandle={this.refreshHandle}
                />
                <InfoPage
                    ref="infoPage"
                    refreshHandle={this.refreshHandle}
                />
            </div>
        )
    }
}
